﻿namespace TwiMixer.Handlers
{
    using System;
    using System.Web;
    using TwiMixer.RESTAPI;

    /// <summary>
    /// 获取request token并重定向用户到服务授权页面
    /// </summary>
    public class OAuthAcquireHandler : IHttpHandler
    {
        /// <summary>
        /// 设置其他请求可以重用这个handler
        /// </summary>
        public bool IsReusable
        {
            get { return true; }
        }

        /// <summary>
        /// 重定向用户到服务授权页面
        /// </summary>
        /// <param name="context">http上下文，用于获取request.parameter</param>
        public void ProcessRequest(HttpContext context)
        {
            APIProviderEnum api = (APIProviderEnum)Enum.Parse(typeof(APIProviderEnum), context.Request.Params["api"]);
            APIProvider provider = (APIProvider)APIProviderFactory.GetApiProvider(api);

            context.Response.Redirect(provider.GetOAuthAuthorizationUrl());
        }
    }
}